package org.example.handler;

import org.example.utils.WebUtils;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Copyright: Copyright (c) 2022 Asiainfo
 *
 * @ClassName: org.example.handler.AuthenticationEntryPointImpl
 * @Description: 认证失败处理类
 * @version: v1.0.0
 * @author: 炫沙糖桔的鹏仔
 * @date: 2022/8/9 15:59
 * <p>
 * Modification History:
 * Date         Author          Version            Description
 * ------------------------------------------------------------
 * 2022/8/9      炫沙糖桔的鹏仔          v1.0.0               修改原因
 */
@Component
public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException {
        WebUtils.renderstring(response, "{\"code\":\"401\",\"msg\":\"认证失败\"}");
    }
}
